﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Infrastructure
{
    public class RandomHelper
    {
        /// <summary>
        /// 生成随机字符串（数字+英文）
        /// </summary>
        /// <param name="b">是否有复杂字符</param>
        /// <param name="n">生成的字符串长度</param>
        /// <returns></returns>
        public static string GetStr(bool b, int n)
        {
            string str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            if (b)
            {
                str += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";//复杂字符
            }
            StringBuilder SB = new StringBuilder();
            Random rd = new Random();
            for (int i = 0; i < n; i++)
            {
                SB.Append(str.Substring(rd.Next(0, str.Length), 1));
            }
            return SB.ToString();
        }
    }
}
